<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>采购订单</title>
<link rel="stylesheet" type="text/css"
	href="../extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="../extjs/ext-all.js"></script>
<script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>
	
<script>
Ext.onReady(function(){
	windowst.show();
	  //加载第一页的信息
	 querybypage(1);
});

//查询
var fielmenu1=new Ext.menu.Menu({
		items:[{text:'历史交易查询',handler:function(){
			//afronction();
			alert(342);
		}}]
	});
//转单
var fielmenua=new Ext.menu.Menu({
		items:[{text:'采购询价单转入',listeners:{  
			 'click':function(){
				//grids.store.removeAll()//清空之前的数据
				alert(231);
			 }
		}},{text:'销售订单转入',listeners:{  
			 'click':function(){
				//grids.store.removeAll()//清空之前的数据
				alert(231);
			 }
		 }},{text:'采购请购单转入',listeners:{  
			 'click':function(){
				//grids.store.removeAll()//清空之前的数据	
			 }
		 }}]
	});
//功能	
var fielmenu2=new Ext.menu.Menu({
		items:[{text:'批次变更单价'}]
	});
//操作
var fielmenu3=new Ext.menu.Menu({
		items:[{text:'上一页',listeners:{  
			 'click':function(){
				grids.store.removeAll()//清空之前的数据
				querybypage(pb.previouspage);
			 }
		}},{text:'下一页',listeners:{  
			 'click':function(){
				grids.store.removeAll()
				querybypage(pb.nextpage);
			}
		}},{text:'新增/修改',listeners:{  
			 'click':function(){
				addoder();
			 }
		}},{text:'删除',listeners:{  
			 'click':function(){	
				deleteoder();
			}
		}},{text:'审核',listeners:{  
			 'click':function(){
				updateshzt();
				updateqgdk();//请购的
			 }
		}},{text:'反审核',listeners:{  
			 'click':function(){
				updateshzt1();
				updateqgcong();//请购的
			 }
		}}]
});

var grids=Ext.create('Ext.grid.Panel',{
	 listeners:{
				containerdblclick: function(grid, e, eOpts){ //单击事件
	    						grid.getStore().add({'name':'12', 'dizhi':'','bianma':'','lianxi':''});
    						
    					},
					itemcontextmenu:function(){
					
    						e.preventDefault();
    						new Ext.menu.Menu({
    							items:[{
    								xtype: 'textfield',
    								text: 'Lost',
    								pressed: false,
    								handler:function(){
											alert();
										}
    							},{
    								xtype: '',
    								text: '娓呴櫎鏂规',
    								pressed: false,
    								handler: function(){}
    							},{
    								xtype: '',
    								text: '閫夋嫨鏂规',
    								pressed: false,
    								menu:new Ext.menu.Menu({
    									items:[{
    										text:'棰勮鏂规',
    										pressed: false
    									}]
    								}),
    								handler: function(){}
    							},{
    								xtype: '',
    								text: '瀵煎嚭鑷矱xcel',
    								pressed: false,
    								handler: function(){}
    							},{
    								xtype: '',
    								text: '缃戞牸鎵撳嵃',
    								pressed: false,
    								handler: function(){}
    							}]
    						}
    						
    						).showAt(e.getXY());
				}
			},plugins: [
        				Ext.create('Ext.grid.plugin.CellEditing', {
            				clicksToEdit: 1
        				})
    				],
		columns: [
				 {header: '（栏号）',
	                    		xtype: 'rownumberer',
	                    		dataIndex: 'serno', 
	                    		width: 80,
								sortable: false
        					},
       			 { header: '物料编号', dataIndex: 'prodId',width: 120,editor: { xtype:'textfield',
				 	listeners:{
						focus:function(grid, e, eOpts){
								windows2.show();
							}
						}
					 }},
					 { header: '折扣前单价',dataIndex: 'oldprice'},
					 { header: '折数(%)', dataIndex: 'discount'},
					 { header: '单价', dataIndex: 'sPrice'},
					 { header: '数量', dataIndex: 'squantity'},
					 { header: '金额', dataIndex: 'amount'},
					 { header: '税率', dataIndex: 'taxrate'},
					 { header: '税额', dataIndex: 'taxamt'},
					 { header: '含税金额', dataIndex: 'vftotal'},
					 { header: '来源单别', dataIndex: 'trantype'},
					 { header: '来源单号', dataIndex: 'fromno'},
					 { header: '预入库日', dataIndex: 'Preindate'},
					 { header: '未入库量', dataIndex: 'qtyremain'}
   					 ],
   			 height: 130,
			 width:1971,
			 autoScroll:false,
			 
})

var filterPanel = Ext.create('Ext.panel.Panel', {
    bodyPadding: 6,  // 避免Panel中的子元素紧邻边框
    width: 1985,
	height:170,
    items:[grids],
	bbar:[{xtype:"label",text:'总计:',width:90},
	{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 203',value:'0.00'},
	{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 12',value:'0.00'},
	{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 50',value:'0.00'},
	{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 12',value:'0.00'}],
});

var form2=Ext.create('Ext.form.Panel', {
    bodyPadding: 5,
	height:'100%',
	layout:"column",
	baseCls:'x-plain',
	items:[{
		 xtype: 'textfield',
        name: 'SalesMan',
		bodyPadding: 5,
        fieldLabel: '账款归属',
		width:250,
        labelWidth: 80,
        anchor: '100%',
			},{
		xtype: 'datefield',
        name: 'Marker',
        format:'Y-m-d',
        fieldLabel: '付款日期',
		style:'margin-left:19px',
		value:Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH,0),"Y-m-d"),
		width:250,
        labelWidth: 80,
        anchor: '100%',
			},
		{
		xtype: 'combobox',
        name: 'Marker',
        fieldLabel: '付款条件',
		width:250,
		valueField: 'abbr',
		displayField:"abbr",
        labelWidth: 80,
        anchor: '100%',
        valueField: 'abbr',
		store: Ext.create('Ext.data.Store', {
			fields: ['abbr', 'name'],
			data : [
				{"abbr":"货到", "name":"货到"},
				{"abbr":"次月", "name":"次月"},
				{"abbr":"月结", "name":"月结"},
				{"abbr":"其他", "name":"其他"}
		   ]
		}),
		value: '货到',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
		},{
		xtype: 'datefield',
        name: 'ProdDepart',
        fieldLabel: '账款月份',
		style:'margin-left:19px',
		 value:Ext.util.Format.date(Ext.Date.add(new Date(),Ext.Date.MONTH,0),"Y-m-d"),
		format:'Y-m',
		width:250,
        labelWidth: 80,
        anchor: '100%',
			}],
	});
	var ppa2 = Ext.create('Ext.panel.Panel', {
    bodyPadding: 6,  // 避免Panel中的子元素紧邻边框
    width: 600,
	height:170,
	items:form2
});

var tableds=Ext.create('Ext.TabPanel',{
		width:"100%",
		height:230,
		autoScroll:true,
		bodyPadding: 5,
		items:[{title:'内容',autoScroll:true,items:[filterPanel]},
		       {title:'账款',autoScroll:true,items:[form2]},
		       {title:'备注',xtype:'textarea',name:'Remark',fieldLabel: '备注',labelWidth: 30,}],
});


var formsg=Ext.create('Ext.form.Panel', {
    bodyPadding: 5,
	height:'100%',
	layout:"column",
	baseCls:'x-plain',
	items:[{
		xtype: 'textfield',
        name: 'salesid',
        id:'salesid',
        fieldLabel: '采购人员',
        style:'margin-left:40px;color:blue',
		width:250,
        labelWidth: 80,
        anchor: '100%',
			},{
		 xtype: 'textfield',
        name: 'maker',
        id:'maker',
        fieldLabel: '制单人员',
		style:'margin-left:18px',
		width:250,
        labelWidth: 80,
        anchor: '100%',
			},{
		xtype: 'textfield',
        name: 'departid',
        id:'departid',
        style:'margin-left:40px;color:blue',
        fieldLabel: '所属部门',
		width:250,
        labelWidth: 80,
        anchor: '100%',
		},{
		 xtype: 'textfield',
        name: 'permitter',
        id:'permitter',
        fieldLabel: '复核人员',
		style:'margin-left:18px',
		width:250,
        labelWidth: 80,
        anchor: '100%',
		},{
				xtype: 'textfield',
		        name: 'projectid',
		        id:'projectid',
		        style:'margin-left:40px;',
		        fieldLabel: '所属项目',
				width:250,
		        labelWidth: 80,
		        anchor: '100%',
			}],
	});
	
var forms=Ext.create('Ext.form.Panel', {
    bodyPadding: 5,
	height:'100%',
	layout:"column",
	baseCls:'x-plain',
	items:[
	  {
		style:"margin-left:40px;color:blue",
		xtype: 'textfield',
        name: 'customerid',
        fieldLabel: '供应商',
        id:'customerid',
		width:250,
        labelWidth: 80,
        anchor: '100%',
		},{
		style:'margin-left:18px;color:blue',
		xtype: 'datefield',
        name: 'billdate',
        fieldLabel: '单据日期',
        id:'billdate',
        format:'Y-m-d',
		width:250,
        labelWidth:80,
        anchor: '100%',
        listeners:{
           blur: function()
           {
               //失去焦点事件
              	alert(Ext.getCmp('billno').getValue());
               //alert (Ext.getCmp('billdate').getValue());
              // Ext.getCmp('billno').getValue()=Ext.getCmp('billdate').getValue()+"01";    
           }
          }
		},{	
			style:'margin-left:40px;',
			xtype: 'textfield',
	        name: 'address',
	        id:'',
	        fieldLabel: '供应商地址',		
			width:150,
	        labelWidth: 80,
	        anchor: '100%',
	        listeners:{
	            blur: function()
	            {
	                //失去焦点事件
	                //alert(Ext.getCmp('validDate').getValue());
	             }
	           }
			},{
    		xtype: 'textfield',
            name: 'dizhiton',
    		width:99,
            labelWidth: 70,
    		margin:"0 1",
            anchor: '100%',
			},{
				xtype: 'textfield',
		        name: 'billno',
		        id:'billno',
				style:"color:blue;margin-left:18px",
		        fieldLabel: '单据号码',
				width:250,
		        labelWidth: 80,
		        anchor: '100%', 
			},{
			style:'margin-left:40px',
			xtype: 'textfield', //多行文本域
	        name: 'billstyle',
	        id:'billstyle',
	        fieldLabel: '采购订单类型',
	        labelWidth: 80,
			width:250,
	        anchor: '100%',
			},{
			    style:'margin-left:18px',
             	fieldLabel: '单价是否含税',
				xtype:'combo',
             	name: 'priceoftax',
             	id:'priceoftax',
             	displayField: 'name',
				labelWidth:80,
				width:250,
				valueField: 'abbr',
				store: Ext.create('Ext.data.Store', {
					fields: ['abbr', 'name'],
					data : [
    					{"abbr":"含税", "name":"含税"},
    					{"abbr":"未税", "name":"未税"}
						
				   ]
				}),
				value: '含税',
    			typeAhead: true,
    			mode: 'local',
    			triggerAction: 'all',
    			selectOnFocus:true,
			},{
			style:'margin-left:40px;color:blue',
			xtype: 'textfield', //多行文本域
	        name: 'currid',
	        id:'currid',
	        fieldLabel: '币别',
	        labelWidth: 80,
			width:250,
	        anchor: '100%',
			
	        },{
	         		style:'margin-left:18px;color:blue',
	         		xtype:'combo',
	                name: 'billstatus',
	                id:'billstatus',
	                fieldLabel: '单况',		
	        		width:250,
	        		displayField: 'name',
	                labelWidth: 80,
	                anchor: '100%',
	            	valueField: 'abbr',
					store: Ext.create('Ext.data.Store', {
						fields: ['abbr', 'name'],
    					data : [
        					{"abbr":"未结案", "name":"未结案"},
        					{"abbr":"已结案", "name":"已结案"}
							
					   ]
					}),
					value: '未结案',
        			typeAhead: true,
        			mode: 'local',
        			triggerAction: 'all',
        			selectOnFocus:true,	
	         	},{
				style:'margin-left:40px',
				xtype: 'textfield', //多行文本域
		        name: 'exchrate',
		        id:'exchrate',
		        fieldLabel: '汇率',
		        labelWidth: 80,
				width:250,
		        anchor: '100%',
	         	},{
	        		style:'margin-left:18px',
	        		xtype: 'textfield',
	                name: 'outaddress',
	                fieldLabel: '送货地址',
	                id:'outaddress',
	        		width:250,
	                labelWidth: 80,
	                anchor: '100%', 
				},tableds,formsg
	]
});

//winform窗口
	var windowst=new  Ext.Window({
		width:640,
		height:530,
		title:"采购订单",
		closable:true,
		resizable:false, //设置是否可以改变大小
		draggable:true,
		anchor: '100%',
		items:[forms],
		bbar:[{xtype:"splitbutton",text:'查询',width:90,menu:fielmenu1},
		     {xtype:"splitbutton",text:'转单',width:90,menu:fielmenua},
			 {xtype:"splitbutton",text:'功能',width:90,menu:fielmenu2},
		     {xtype:"splitbutton",text:'操作',width:90,menu:fielmenu3}],	  
		});
	
	
	//定义分页的全局变量pb
	var pb = null;
	
	//封装查询分页方法
	function querybypage(num)
	{
		Ext.Ajax.request({  
	        //被用来向服务器发起请求默认的url  
	        url : "/zj/querybypage",  
	        //请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
	        params :{pagenum:num},  
	        //请求时使用的默认的http方法  
	        method : "post",  
	        //请求成功时回调函数  
	        success : function(data) {  
	        	pb=Ext.JSON.decode(data.responseText)
	        	Ext.getCmp('billno').setValue(pb.pagedata[0].billno);
				Ext.getCmp('customerid').setValue(pb.pagedata[0].customerid);
				Ext.getCmp('billdate').setValue(pb.pagedata[0].billdate);
				Ext.getCmp('currid').setValue(pb.pagedata[0].currid);
				Ext.getCmp('exchrate').setValue(pb.pagedata[0].exchrate);
				Ext.getCmp('outaddress').setValue(pb.pagedata[0].outaddress);
				Ext.getCmp('priceoftax').setValue(pb.pagedata[0].priceoftax);
				Ext.getCmp('Billstatus').setValue(pb.pagedata[0].Billstatus);
				Ext.getCmp('maker').setValue(pb.pagedata[0].maker);
				Ext.getCmp('salesid').setValue(pb.pagedata[0].salesid);
				Ext.getCmp('permitter').setValue(pb.pagedata[0].permitter);
				Ext.getCmp('departname').setValue(pb.pagedata[0].departname);
				Ext.getCmp('projectid').setValue(pb.pagedata[0].projectid);
	
				grids.getStore().add(pb.pagedata[0].order);
				
	        },
	        //请求失败时回调函数  
	        failure : function() {  
	        	Ext.Msg.alert("信息提示", "数据不正确!!");  
	        }  
		});  	
	}
	
	//封装新增方法
	function addoder()
	{
		var bc={};
		bc['billno'] = Ext.getCmp('billno').getValue();
		bc['customerid'] = Ext.getCmp('customerid').getValue();
		bc['billdate'] = Ext.getCmp('billdate').getValue();
		bc['Billstatus'] = Ext.getCmp('Billstatus').getValue();
		//bc['Shifoushenhe'] = Ext.getCmp('Shifoushenhe').getValue();
		bc['priceoftax'] = Ext.getCmp('priceoftax').getValue();
		//bc['Sumtotal'] = Ext.getCmp('Sumtotal').getValue();
		bc['currid'] = Ext.getCmp('currid').getValue();
		bc['exchrate'] = Ext.getCmp('exchrate').getValue();
		bc['outaddress'] = Ext.getCmp('outaddress').getValue();
		bc['departname'] = Ext.getCmp('departname').getValue();
		bc['maker'] = Ext.getCmp('maker').getValue();
		bc['salesid'] = Ext.getCmp('salesid').getValue();
		bc['permitter'] = Ext.getCmp('permitter').getValue();
		bc['projectid'] = Ext.getCmp('projectid').getValue();
		
		//详表
		bc['order'] = Ext.pluck(grids.getStore().data.items,'data');
		
		alert(JSON.stringify(bc));
		
		Ext.Ajax.request({  
	        //被用来向服务器发起请求默认的url  
	        url : "/zj/addoder",
	        //请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串 
	       	headers: {'Content-Type':'application/json'},
	        params :JSON.stringify(bc),  
	        //请求时使用的默认的http方法  
	        method : "post",
	        //请求成功时回调函数  
	        success : function(){
	        	Ext.Msg.alert("信息提示","新增成功!!!");      
	        },
	        failure:function(){
	        	Ext.Msg.alert("信息提示","新增失败");
	        }
		});  
	}
	
	//封装删除方法
	function deleteoder()
	{
		alert(Ext.getCmp('billno').getValue());
		Ext.Ajax.request({   
              url:"/zj/deleteoder?billno="+Ext.getCmp('billno').getValue()+"", 
              success:function(){   
              Ext.Msg.alert("信息提示","您已经成功删除该信息！");      
              },   
              failure:function(){   
                 Ext.Msg.alert('错误','删除失败！！！');   
               }   
             });              
             Ext.Msg.alert('删除操作','请选择一行你要删除的数据！');     
	}
	
	//封装主表的审核方法
	function updateshzt()
	{
		Ext.Ajax.request({   
              url:"/zj/updateshzt?id="+Ext.getCmp('billno').getValue()+"",
              success:function(){   
              	Ext.Msg.alert("信息提示","审核成功！");      
              },   
              failure:function(){   
                 Ext.Msg.alert('错误','审核失败！');   
               }   
            });              
	}
	
	//封装主表的反审核方法
	function updateshzt1()
	{
		Ext.Ajax.request({
              url:"/zj/updateshzt1?id="+Ext.getCmp('billno').getValue()+"",  
              success:function(){   
              	Ext.Msg.alert("信息提示","反审核成功！");      
              },   
              failure:function(){   
                 Ext.Msg.alert('错误','反审核失败！');   
               }   
            });              
	}
	

	//封装修改请购表的单况方法（审核）
	function updateqgdk()
	{
		Ext.Ajax.request({   
              url:"/zj/updateqgdk?id="+Ext.getCmp('billno').getValue()+"",
              success:function(){   
              	Ext.Msg.alert("信息提示","修改成功！");      
              },   
              failure:function(){   
                 Ext.Msg.alert('错误','修改失败！');   
               }   
            });              
	}
	
	//封装修改请购表的单况方法（反审核）
	function updateqgcong()
	{
		Ext.Ajax.request({
              url:"/zj/updateqgcong?id="+Ext.getCmp('billno').getValue()+"",  
              success:function(){   
              	Ext.Msg.alert("信息提示","修改成功！");      
              },   
              failure:function(){   
                 Ext.Msg.alert('错误','修改失败！');   
               }   
            });              
	}
</script>
</head>
<body>
</body>

</html>